﻿$(function () {
    applyMask();
});

function disableFields(fields, disable) {
    if (disable)
        fields.attr("disabled", "disabled");
    else
        fields.removeAttr("disabled");
}

function applyMask() {
    $('.date').mask('99/99/9999', { autoTab: false }); //.datepicker();
    $('.integer').mask('9999999999', { autoTab: false });
    $('.long').mask('999999999999999999', { autoTab: false });
    $('.percent').mask('99,999', { type: 'reverse', defaultValue: '000', autoTab: false });
    $('.percentNullable').mask('99,999', { type: 'reverse', autoTab: false });
    $('.percentNegative').mask('99,999', { type: 'reverse', defaultValue: '+000', autoTab: false });
    $('.valueNegative').mask('99,999.999.999.999', { type: 'reverse', defaultValue: '+000', autoTab: false });
    $('.valueNullable').mask('99,999.999.999.999', { type: 'reverse', defaultValue: '+', autoTab: false });
    $('.hour').mask('99:99:99', { autoTab: false });
    $('.day').mask('99', { autoTab: false });
    $('.value').mask('99,999.999.999.999', { type: 'reverse', defaultValue: '+000', autoTab: false });
    $('.year').mask('9999', { autoTab: false });

//    $(".date").keydown(function (e) {
//        return false;
//    }); 
}

function formatBoolean(cellValue, options, rowData) {
    return cellValue ? 'Yes' : 'No';
}

function textAreaMaxLength(selector, maxLength) {
    if (!maxLength) {
        maxLength = 255;
    }

    $(selector).maxlength({
        maxCharacters: maxLength,
        status: true,
        statusClass: 'textAreaStatus',
        statusText: 'characters left',
        showAlert: false
    });
}
